package cn.sofwin.core.mvc.support.bean.info;

import java.io.Serializable;
import java.util.HashMap;
import java.util.LinkedHashMap;
import java.util.Map;

/**
 * 模块信息
 * @author LetCode
 * @since 1.0
 */
public class Module implements Serializable {

    /** 模块元信息 */
    private Meta meta;

    /** 功能选项 */
    private Action action;

    /** 视图列表 */
    private Map<String, String> view;

    /** API列表 */
    private Map<String, String> api;

    /** 搜索字段 */
    private Map<String, String> searchFields;

    public Module() {
        this.meta = new Meta();
        this.action = new Action();
        this.view = new HashMap<>();
        this.api = new HashMap<>();
        this.searchFields = new LinkedHashMap<>();
    }

    /**
     * 根据元信息初始化
     * @param title
     * @param code
     */
    public Module(String title, String code) {
        this();
        this.meta = new Meta(title, code);
    }

    /**
     * 增加列信息
     * @param field
     * @param title
     * @return
     */
    public Module addColumn(String field, String title){
        this.meta.addColumn(field, title);
        return this;
    }

    /**
     * 添加搜索字段
     * @param field
     * @param title
     * @return
     */
    public Module addSearchField(String field, String title){
        this.searchFields.put(field, title);
        return this;
    }

    /**
     * 添加视图
     * @param code
     * @param url
     * @return
     */
    public Module addView(String code, String url){
        view.put(code, url);
        return this;
    }

    /**
     * 添加API地址
     * @param action
     * @param url
     */
    public Module addApi(String action, String url){
        api.put(action, url);
        return this;
    }

    public Meta getMeta() {
        return meta;
    }

    public void setMeta(Meta meta) {
        this.meta = meta;
    }

    public Map<String, String> getSearchFields() {
        return searchFields;
    }

    public void setSearchFields(Map<String, String> searchFields) {
        this.searchFields = searchFields;
    }

    public Action getAction() {
        return action;
    }

    public void setAction(Action action) {
        this.action = action;
    }

    public Map<String, String> getView() {
        return view;
    }

    public void setView(Map<String, String> view) {
        this.view = view;
    }

    public Map<String, String> getApi() {
        return api;
    }

    public void setApi(Map<String, String> api) {
        this.api = api;
    }
}